﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : MonoBehaviour {

    public float speed = 10;
    private Transform[] position;
    private int index = 0;

	// Use this for initialization
	void Start () {
        position = WayPoints.positions;
	}
	
	// Update is called once per frame
	void Update () {
        Move();
	}

    void Move()
    {
        if (index > position.Length - 1)
            return;

        transform.Translate((position[index].position - transform.position).normalized * Time.deltaTime * speed);
        if (Vector3.Distance(position[index].position, transform.position) < 0.2f)
        {
            index++;
        }
        if (index > position.Length - 1)
        {
            ReachDestination();
        }
    }

    void ReachDestination()
    {
        GameObject.Destroy(this.gameObject);
        //Debug.Log("到达终点");
    }

    void OnDestroy()
    {
        EnemySpawner.CountEnemyAlive--;
    }

    public void TakeDamage(int damage)
    {

    }
}
